package com.navercorp.pinpoint.web.util;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;

public class BeanUtils {

    /**
     * 字节数组转为Object对象
     *
     * @param bytes
     * @return
     */
    public static Object byteToObj(byte[] bytes) {
        Object readObject = null;
        try (ByteArrayInputStream in = new ByteArrayInputStream(bytes);
             ObjectInputStream inputStream = new ObjectInputStream(in)){
            readObject = inputStream.readObject();
        } catch (Exception e) {
            e.printStackTrace();
            //反序列化失败，则直接结束程序，保证数据完整
            System.err.println("反序列化对象失败！");
            System.exit(0);
        }
        return readObject;
    }
}
